package com.new4net.exe_stream.service.impl;

import com.new4net.exe_stream.service.ExecutionLog;
import com.new4net.exe_stream.service.ExecutionLogService;
import com.sun.deploy.util.StringUtils;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ConsoleExecutionLogService implements ExecutionLogService {


    @Override
    public void record(ExecutionLog executionLog) {
        if("ERROR".equals(executionLog.getType())){
            String format = String.format("执行流%s(%s),在执行到%s(%s)时产生错误,错误内容为："
                    , executionLog.getExecutionId()
                    , executionLog.getExecutionName()
                    , executionLog.getInstructionId()
                    , executionLog.getInstructionName());
            log.error(format,executionLog.getError());
//            System.out.println(format);
//            executionLog.getError().printStackTrace();
        }else{
            String format ;
            if("IN".equals(executionLog.getType())){
                format = String.format("当前执行流%s(%s),进入%s(%s)"
                        , executionLog.getExecutionId()
                        , executionLog.getExecutionName()
                        , executionLog.getInstructionId()
                        , executionLog.getInstructionName());

            }else{
                format = String.format("当前执行流%s(%s),退出%s(%s)"
                        , executionLog.getExecutionId()
                        , executionLog.getExecutionName()
                        , executionLog.getInstructionId()
                        , executionLog.getInstructionName());
            }
            if(!("".equals(executionLog.getStepName())||executionLog.getStepName()==null)){
                format+=",当前步骤为:"+executionLog.getStepName();

            }
            log.info(format);

//            System.out.println(format);
        }

    }


}
